package com.xauto.pioneer.appuser.util;

import android.content.Context;
import android.util.Log;

import com.xauto.pioneer.appuser.model.Payment;

import net.tsz.afinal.FinalDb;

import java.util.List;

/**
 * Created by Ellis.Li on 2017/5/12.
 */

public class DbUtil<T> {
    static  DbUtil dbUtil;
    static Context mContext;
    public static DbUtil getInstance(Context cxt){
        if (dbUtil == null){
            synchronized (DbUtil.class) {
                mContext = cxt;
                dbUtil = new DbUtil();
            }
        }
        return dbUtil;
    }

    /**
     *获取存储在db种的对象列表
     * 用法：
     List<Bank> bankList = DbUtil.getInstance(mContext).getDataList(Bank.class);
     * @param v
     * @return
     */
    public List<T> getDataList(T v){
        FinalDb finalDb = FinalDb.create(mContext);
        List<T> list = (List<T>) finalDb.findAll((Class<? extends Object>) v);
        Log.d("Dbutil","size: "+list.size());
        return list;
    }
}
